package cn.ac.iie.di.ban.ycl.cleaner;

import cn.ac.iie.di.ban.ycl.cleaner.common.Constants;
import org.apache.commons.configuration2.FileBasedConfiguration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Parameters;
import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
import org.apache.commons.configuration2.ex.ConfigurationException;

/**
 * @author zmc <zhangmingcheng@iie.ac.cn>
 * @date 2016-9-18 14:30:49
 * @version V1.0
 * @desc
 */
public class Configuration {

    public static void main(String[] args) throws ConfigurationException {
        String propertiesPath = Configuration.class.getResource("/").getFile() + "/configuration.properties";
        System.out.println("properties path:" + propertiesPath);
        Parameters params = new Parameters();
        FileBasedConfigurationBuilder<FileBasedConfiguration> confBuilder
                = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
                        PropertiesConfiguration.class)
                .configure(params.properties()
                        .setFileName(propertiesPath)
                        .setListDelimiterHandler(new DefaultListDelimiterHandler(','))
                        .setThrowExceptionOnMissing(true));
        FileBasedConfiguration configuration = confBuilder.getConfiguration();

        String mqNameserver = configuration.getString(Constants.RECEIVER_MQ_NAMESERVER);
        String mqTopic = configuration.getString(Constants.RECEIVER_MQ_READ_TOPIC);
        String mqGroup = configuration.getString(Constants.RECEIVER_MQ_GROUP);

        int corePoolSize = configuration.getInt(Constants.HANDLER_THREAD_NUM);

       System.out.println("--------------------------------------------");
       System.out.println("         mq nameserver = " + mqNameserver);
       System.out.println("              mq topic = " + mqTopic);
       System.out.println("              mq group = " + mqGroup);
       System.out.println("thread core pool size  = " + corePoolSize);
       System.out.println("--------------------------------------------");
    }
}
